package ningbo.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/**
 * @Author 宁铂
 * @Date 2021/7/28 9:34
 * @Version 1.0
 */
public class TestArrayList {
    /** 用于测试Arraylist */
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();

        arrayList.add(100);
        arrayList.add(200);
        arrayList.add(300);
        arrayList.add(400);
        arrayList.add(400);
        arrayList.add(500);
        System.out.println(arrayList);

        //判断集合中是否包含指定元素
        arrayList.contains(100);

        //判断集合是否为空
        arrayList.isEmpty();

        //获取指定下表的元素
        arrayList.get(5);

        //删除指定下标的元素
        arrayList.remove(1);

        //根据元素删除元素,想要把基本类型的的500手动装箱成包装类性
        arrayList.remove(Integer.valueOf(500));

        //获取集合中元素个数
        arrayList.size();

        //修改指定下标的元素
        arrayList.set(3, 600);

        //获取元素开始和结束的下标
        arrayList.indexOf(500);
        arrayList.lastIndexOf(500);

        //集合的迭代(遍历)
        for (int i = 0; i <= arrayList.size()-1; i++)
            System.out.println(arrayList.get(i));

        for (Integer integer : arrayList) {
            System.out.println(integer);
        }

        Iterator<Integer> iterator = arrayList.iterator();
        while (iterator.hasNext())
            System.out.println(iterator.next());

        ListIterator<Integer> integerListIterator = arrayList.listIterator();
        while (integerListIterator.hasNext())
            System.out.println(integerListIterator.next());
    }

}
